{extend name="public/base"}
{block name='main'}
<blockquote class="layui-elem-quote">
    <b>{$addon.tips.title|default=''}</b><br>
    {$addon.tips.value|default=''}
</blockquote>

<form action="{:url('config')}" class="layui-form" method="post">
      {empty name="custom_config"}
      {foreach name="$addon.config" id="config" key="o_key"}
        <div class="layui-form-item">
        {notempty name="config.title"}
        <label class="layui-form-label">{$config.title|default=''}</label>
        {/notempty}
        {switch name="config.type"}

        {case value="text"}
        <div class="layui-input-block w500">
          <input type="text" name="config[{$o_key}]" value="{$config.value}" class="layui-input">
          {notempty name="config.tip"}
          <div class="layui-form-mid layui-word-aux">{$config.tip}</div>
          {/notempty}
        </div>
        {/case}

        {case value="password"}
        <div class="layui-input-block w500">
          <input type="password" name="config[{$o_key}]" value="{$config.value}" class="layui-input">
          {notempty name="config.tip"}
          <div class="layui-form-mid layui-word-aux">{$config.tip}</div>
          {/notempty}
        </div>
        {/case}

        {case value="radio"}
        <div class="layui-input-block w500">
          {foreach name="config['options']" key="opt_k" item="vo"}
          <input type="radio" name="config[{$o_key}]" value="{$opt_k}" title="{$vo}" {eq name="config.value" value="$opt_k"} checked{/eq}>
          {/foreach}
          {notempty name="config.tip"}
          <div class="layui-form-mid layui-word-aux">{$config.tip}</div>
          {/notempty}
        </div>
        {/case}
        {case value="checkbox"}
        <div class="layui-input-block w500">
          {foreach name="config['options']" key="opt_k" item="vo"}
          <input type="checkbox" name="config[{$o_key}][]" value="{$opt_k}" title="{$vo}" {eq name="config.value" value="$opt_k"} checked{/eq}>
          {/foreach}
          {notempty name="config.tip"}
          <div class="layui-form-mid layui-word-aux">{$config.tip}</div>
          {/notempty}
        </div>
        {/case}
        {case value="select"}
        <div class="layui-input-inline">
          <select name="config[{$o_key}]">
            {foreach name="config['options']" key="opt_k" item="vo"}
            <option value="{$opt_k}" {eq name="config.value" value="$opt_k"}selected{/eq}>{$vo}</option>
            {/foreach}
          </select>
        </div>
        {notempty name="config.tip"}
        <div class="layui-form-mid layui-word-aux">{$config.tip}</div>
        {/notempty}
        {/case}
        {case value="textarea"}
        <div class="layui-input-block">
          <textarea name="config[{$o_key}]" class="layui-textarea">{$config.value}</textarea>
          {notempty name="config.tip"}
          <div class="layui-form-mid layui-word-aux">{$config.tip}</div>
          {/notempty}
        </div>
        {/case}
        {case value="copy"}
        <div class="layui-input-block w500">
          <div class="input-group">
            <input type="text" name="config[{$o_key}]" id="copy_text_{$o_key}" style="width:436px;" class="layui-input" value="{$config.value}">
            <button class="layui-btn" data-clipboard-target="#copy_text_{$o_key}" type="button" title="复制">复制</button>
          </div>
          {notempty name="config.tip"}
          <div class="layui-form-mid layui-word-aux">{$config.tip}</div>
          {/notempty}
        </div>
        {/case}
        {case value="hidden"}
        <input type="hidden" name="config[{$o_key}]" value="{$config.value}">
        {/case}
        {case value="picture"}
        <div class="layui-input-block w500">
          <div class="input-group">
            <input type="text" size="52" name="config[{$o_key}]" value="{$config.value}" class="layui-input">
            <button class="layui-btn" id="upload_{$o_key}" type="button">上传图片</button>
          </div>
        </div>
        {notempty name="config.tip"}
        <div class="layui-form-mid layui-word-aux">{$config.tip}</div>
        {/notempty}
        <script type="text/javascript">
          layui.use(['layer','upload','jquery'], function(){
            var layer = layui.layer;
            var upload = layui.upload;
            var uploadInst = upload.render({
              elem: '#upload_{$o_key}' //绑定元素
              ,url: '{:url('upload/pic')}' //上传接口
                    ,data: {path:'addons'}
          ,done: function(data){
              if(data.code){
                layer.msg(data.msg, {icon: 1,shade: 0.3,time: 2000},function(layero, index){
                  $('[name="config[{$o_key}]"]').val(data.data.path);
                });
              }else{
                layer.msg(data.msg, {icon: 0,shade: 0.3});
              }
            }
          ,error: function(){
              //请求异常回调
            }
          });
          });
        </script>
        {/case}
        {case value="group"}
        <div class="layui-tab">
          <ul class="layui-tab-title">
            {volist name="config.options" id="li"}
            <li {eq name="i" value="1"}class="layui-this"{/eq}>{$li.title}</li>
            {/volist}
          </ul>
          <div class="layui-tab-content">
            {volist name="config.options" id="tab"}
            <div class="layui-tab-item {eq name="i" value="1"}layui-show{/eq}">
            {foreach name="tab['options']" item="tab_form" key="o_tab_key"}
            <div class="layui-form-item">
              <label class="layui-form-label">{$tab_form.title|default=''}</label>
              {switch name="tab_form.type"}
              {case value="text"}
              <div class="layui-input-block w500">
                <input type="text" name="config[{$o_tab_key}]" value="{$tab_form.value}" class="layui-input">
                {notempty name="tab_form.tip"}
                <div class="layui-form-mid layui-word-aux">{$tab_form.tip}</div>
                {/notempty}
              </div>
              {/case}
              {case value="password"}
              <div class="layui-input-block w500">
                <input type="password" name="config[{$o_tab_key}]" value="{$tab_form.value}" class="layui-input">
                {notempty name="tab_form.tip"}
                <div class="layui-form-mid layui-word-aux">{$tab_form.tip}</div>
                {/notempty}
              </div>
              {/case}
              {case value="radio"}
              <div class="layui-input-block w500">
                {foreach name="tab_form['options']" key="opt_k" item="vo"}
                <input type="radio" name="config[{$o_tab_key}]" value="{$opt_k}" title="{$vo}" {eq name="tab_form.value" value="$opt_k"} checked{/eq}>
                {/foreach}
                {notempty name="tab_form.tip"}
                <div class="layui-form-mid layui-word-aux">{$tab_form.tip}</div>
                {/notempty}
              </div>
              {/case}
              {case value="checkbox"}
              <div class="layui-input-block w500">
                {foreach name="tab_form['options']" key="opt_k" item="vo"}
                <input type="checkbox" name="config[{$o_tab_key}][]" value="{$opt_k}" title="{$vo}" {eq name="tab_form.value" value="$opt_k"} checked{/eq}>
                {/foreach}
                {notempty name="tab_form.tip"}
                <div class="layui-form-mid layui-word-aux">{$tab_form.tip}</div>
                {/notempty}
              </div>
              {/case}
              {case value="select"}
              <div class="layui-input-inline">
                <select name="config[{$o_tab_key}]">
                  {foreach name="tab_form['options']" key="opt_k" item="vo"}
                  <option value="{$opt_k}" {eq name="tab_form.value" value="$opt_k"}selected{/eq}>{$vo}</option>
                  {/foreach}
                </select>
              </div>
              {notempty name="tab_form.tip"}
              <div class="layui-form-mid layui-word-aux">{$tab_form.tip}</div>
              {/notempty}
              {/case}
              {case value="textarea"}
              <div class="layui-input-block">
                <textarea name="config[{$o_tab_key}]" class="layui-textarea" placeholder="{$tab_form.tip}">{$tab_form.value}</textarea>
                {notempty name="tab_form.tip"}
                <div class="layui-form-mid layui-word-aux">{$tab_form.tip}</div>
                {/notempty}
              </div>
              {/case}
              {case value="copy"}
              <div class="layui-input-block w500">
                <div class="input-group">
                  <input type="text" name="config[{$o_tab_key}]" id="copy_text_{$o_tab_key}" style="width:408px;" class="layui-input" value="{$tab_form.value}">
                  <button class="layui-btn" data-clipboard-target="#copy_text_{$o_tab_key}" type="button" title="复制">复制</button>
                </div>
                {notempty name="tab_form.tip"}
                <div class="layui-form-mid layui-word-aux">{$tab_form.tip}</div>
                {/notempty}
              </div>
              {/case}
              {case value="hidden"}
              <input type="hidden" name="config[{$o_tab_key}]" value="{$tab_form.value}">
              {/case}
              {case value="picture"}
              <div class="layui-input-block w500">
                <div class="input-group">
                  <input type="text" size="52" name="config[{$o_tab_key}]" value="{$tab_form.value}" class="layui-input">
                  <button class="layui-btn" id="upload_{$o_tab_key}" type="button">上传图片</button>
                </div>
              </div>
              {notempty name="tab_form.tip"}
              <div class="layui-form-mid layui-word-aux">{$tab_form.tip}</div>
              {/notempty}
              <script type="text/javascript">
                layui.use(['layer','upload','jquery'], function(){
                  var layer = layui.layer;
                  var upload = layui.upload;
                  var uploadInst = upload.render({
                    elem: '#upload_{$o_tab_key}' //绑定元素
                    ,url: '{:url('upload/pic')}' //上传接口
                          ,data: {path:'addons'}
                ,done: function(data){
                    if(data.code){
                      layer.msg(data.msg, {icon: 1,shade: 0.3,time: 2000},function(layero, index){
                        $('[name="config[{$o_tab_key}]"]').val(data.data.path);
                      });
                    }else{
                      layer.msg(data.msg, {icon: 0,shade: 0.3});
                    }
                  }
                ,error: function(){
                    //请求异常回调
                  }
                });
                });
              </script>
              {/case}
              {/switch}
            </div>
            {/foreach}
          </div>
          {/volist}
        </div>
      </div>
      {/case}
      {/switch}
  </div>
  {/foreach}
  {else/}
  {$custom_config}
  {/empty}

  <div class="layui-form-item">
    <label class=""></label>
    <div class="layui-input-block">
      <button class="layui-btn" lay-submit="" lay-filter="content_edit">提交保存</button>
    </div>
  </div>
</form>
<script type="text/javascript" src="__PUBLIC__/admin/layui/layui.js"></script>
<script>
  layui.use(['layer','jquery','form','element','layedit'], function () {
    //参数：layui、名称、更新的formid、更新的url：module/method、更新后跳转的url（为空则不跳转）、编辑器id、标签id（为空则不获取）
    Oper.initUpdate(layui, '导航', 'content_edit', 'nav/add');
  });
</script>
{/block}